﻿<Window x:Class="Profit.Views.SettingsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:local="clr-namespace:Profit.Controls"
        xmlns:enums="clr-namespace:Profit.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:Resources="clr-namespace:Profit.Resources" 
        mc:Ignorable="d" 
        d:DesignHeight="260" 
        d:DesignWidth="380" 
        Icon="/Profit;component/Resources/Icons/app_32.ico"
        SizeToContent="WidthAndHeight"
        MinWidth="400"
        MinHeight="260">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="0" Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="150"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <Label 
                Grid.Row="0"
                Grid.Column="0"
                VerticalAlignment="Center"
                Margin="5,2"
                Content="{x:Static Resources:Messages.settings_check_new_version}" />
            <CheckBox 
                Grid.Row="0"
                Grid.Column="1"
                VerticalAlignment="Center"
                IsChecked="{Binding Default.CheckNewVersionOnStartup, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

            <Label 
                Grid.Row="1"
                Grid.Column="0"
                VerticalAlignment="Center"
                Margin="5,2"
                Content="{x:Static Resources:Messages.settings_auto_save_fittings}" />

            <CheckBox 
                Grid.Row="1"
                Grid.Column="1"
                VerticalAlignment="Center"
                IsChecked="{Binding Default.SaveFittingsOnExit, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

            <Label 
                Grid.Row="2"
                Grid.Column="0"
                VerticalAlignment="Center"
                Margin="5,2"
                Content="{x:Static Resources:Messages.settings_use_log}" />
            
            <Grid 
                Grid.Row="2"
                Grid.Column="1" Grid.ColumnSpan="2">
               
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                
                <CheckBox x:Name="checkboxUseLog"
                    Grid.Column="0"
                    VerticalAlignment="Center"
                    IsChecked="{Binding Default.UseLog, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                <TextBlock
                    Grid.Column="1"
                    Margin="5,0,0,0"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Stretch"
                    TextTrimming="CharacterEllipsis"
                    Visibility="{Binding ElementName=checkboxUseLog, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"
                    Text="{Binding Default.PathLog, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource PathToFullPathConverter}}"/>

                <Button
                    Grid.Column="2"
                    Style="{StaticResource FlatButtonStyle}"
                    Visibility="{Binding ElementName=checkboxUseLog, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"
                    Command="{Binding SelectFolderCommand}"
                    CommandParameter="{x:Static enums:FolderTypeEnum.Log}"
                    Width="16"
                    Height="16"
                    Margin="2,0"
                    ToolTip="{x:Static Resources:Messages.label_select_directory}"
                    VerticalAlignment="Center" >
                    <Image Source="/Profit;component/Resources/Icons/folder.png" />
                </Button>

            </Grid>
            
            <Label 
                Grid.Row="4"
                Grid.Column="0"
                VerticalAlignment="Center"
                Margin="5,2"
                Content="{x:Static Resources:Messages.settings_agents_directory}" />

            <TextBlock 
                Grid.Row="4"
                Grid.Column="1"
                Margin="1,2"
                VerticalAlignment="Center"
                TextTrimming="CharacterEllipsis"
                Text="{Binding Default.PathAgents, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource PathToFullPathConverter}}"/>

            <Button
                Grid.Row="4"
                Grid.Column="2"
                Style="{StaticResource FlatButtonStyle}"
                Width="16"
                Height="16"
                Margin="1,2"
                ToolTip="{x:Static Resources:Messages.label_select_directory}"
                VerticalAlignment="Center" 
                Command="{Binding SelectFolderCommand}"
                CommandParameter="{x:Static enums:FolderTypeEnum.Agents}">
                <Image Source="/Profit;component/Resources/Icons/folder.png" />
            </Button>

            <Label 
                Grid.Row="5"
                Grid.Column="0"
                VerticalAlignment="Center"
                Margin="5,2"
                Content="{x:Static Resources:Messages.settings_fittings_directory}" />

            <TextBlock 
                Grid.Row="5"
                Grid.Column="1"
                Margin="1,2"
                VerticalAlignment="Center"
                TextTrimming="CharacterEllipsis"
                Text="{Binding Default.PathFittings, Source={StaticResource AppSettings}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource PathToFullPathConverter}}"/>

            <Button
                Grid.Row="5"
                Grid.Column="2"
                Style="{StaticResource FlatButtonStyle}"
                Width="16"
                Height="16"
                Margin="1,2"
                ToolTip="{x:Static Resources:Messages.label_select_directory}"
                VerticalAlignment="Center"
                Command="{Binding SelectFolderCommand}"
                CommandParameter="{x:Static enums:FolderTypeEnum.Fittings}">
                <Image Source="/Profit;component/Resources/Icons/folder.png" />
            </Button>
            
        </Grid>
        
        
        <Button 
            Grid.Row="1"
            Grid.Column="0"
            Margin="11,0"
            Style="{StaticResource DialogButtonStyle}"
            Content="{x:Static Resources:Messages.settings_restore_defaults}"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            ToolTip="{x:Static Resources:Messages.settings_tooltip_restore_defaults}"
            Command="{Binding ResetCommand}" />
        <local:DialogActionsPanel
            Grid.Row="1" 
            Grid.Column="1"
            HorizontalAlignment="Right"
            VerticalAlignment="Bottom"
            ShowButtonCancel="True"
            ButtonCancelContent="{x:Static Resources:Messages.label_close}"
            ButtonOkContent="{x:Static Resources:Messages.label_save}"
            ButtonOkCommand="{Binding ValidateCommand}" />
    </Grid>
</Window>
